/**
 * 数据库连接
 */
const mysql = require('mysql');
const config = require('./index');
const conn = mysql.createConnection(config);

conn.connect(e => {
  if (e) {
    throw e;
  }
  console.log('mysql connected...');
})

const query = (sql, params) => {
  return new Promise((resolve, reject) => {
    conn.query(sql, params, (e, res) => {
      if (e) {
        console.log(e, 1);
        reject(e);
      } else {
        resolve(res);
      }
    })
  })
}

module.exports = { conn, query };